# 1. 项目基本设置
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(sysmonitor_lib VERSION 0.1.0 LANGUAGES CXX)

# 2. C++ 标准和编译选项
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_library(sysmonitor_lib STATIC
    src/cpu_tools.cpp
    src/file_system.cpp
    src/memory_tools.cpp
    src/network_tools.cpp
    src/resources_monitor.cpp
    src/utils.cpp
)

# 4. 为库目标设置头文件目录
target_include_directories(sysmonitor_lib PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
)

# 5. 为库目标链接依赖
target_link_libraries(sysmonitor_lib PUBLIC pthread)

# 6. 添加示例可执行文件
add_executable(monitor_example example/example.cpp)

# 7. 链接我们的库到示例程序
target_link_libraries(monitor_example PRIVATE sysmonitor_lib)

# 8. 安装规则
install(TARGETS sysmonitor_lib
    EXPORT ${PROJECT_NAME}-targets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
)
install(DIRECTORY include/ DESTINATION .)
install(EXPORT ${PROJECT_NAME}-targets
    FILE ${PROJECT_NAME}-config.cmake
    NAMESPACE sysmonitor::
    DESTINATION lib/cmake/${PROJECT_NAME}
)
install(TARGETS monitor_example DESTINATION bin)
